<?php
set_include_path("../include;include");
require_once '/dao/PriceCategoryDAO.php';

class PriceCategory {
	private $id;
	private $event;
	private $group;
	private $name;
	private $description;
	private $cost;
	
	function __construct(Event $event) {
		$this->event = $event;
	}
	
	public function load(integer $id) {
		$dao = PriceCategoryDAO::getInstance();
		
		$this->id = $id;
		$this->event = Event::loadEvent($dao->getEventIdByPriceCategoryId($id));
		$this->group = Group::loadGroup($dao->getGroupIdByPriceCategoryId($id));
		$this->name = $dao->getNameByPriceCategoryId($id);
		$this->description = $dao->getDescriptionByPriceCategoryId($id);
		$this->cost = $dao->getCostByPriceCategoryId($id);	
	}
	
	public function save() {
		$dao = PriceCategoryDAO::getInstance();
		
		$priceCat_id = $dao->save($this);
		return $priceCat_id;
	}
	
	public static function createNew(Event $event, Group $group, string $name, string $description, double $cost) {
		$pricecat = new self($event);
		$pricecat->group = $group;
		$pricecat->name = $name;
		$pricecat->description = $description;
		$pricecat->cost = $cost;
		return $pricecat;
	}
	
	public static function loadPriceCategory(Event $event, integer $id) {
		$dao = PriceCategoryDAO::getInstance();
		
		$pricecat = new self($event);
		
		$pricecat->id = $id;
		$pricecat->event = Event::loadEvent($dao->getEventIdByPriceCategoryId($id));
		$pricecat->group = Group::loadGroup($dao->getGroupIdByPriceCategoryId($id));
		$pricecat->name = $dao->getNameByPriceCategoryId($id);
		$pricecat->description = $dao->getDescriptionByPriceCategoryId($id);
		$pricecat->cost = $dao->getCostByPriceCategoryId($id);
		
		return $pricecat;
	}
	
	public static function loadPriceCategoryFor(Registration $registration, Participant $participant) {
		$dao = PriceCategoryDAO::getInstance();
		
		return $dao->getPriceCategoryFor($registration->getId(), $participant->getId());
	}
	
	public static function getPriceCategoriesFor(Event $event) {
		$dao = PriceCategoryDAO::getInstance();
		
		return $dao->getPriceCategoriesFor($event);
	}

	public function getId() {
		return $this->id;
	}
	
	public function setId(integer $id) {
		$this->id = $id;
	}
	
	public function getEvent() {
		return $this->event;
	}
	
	public function setEvent(Event $event) {
		$this->event = $event;
	}
	
	public function getGroup() {
		return $this->group;
	}
	
	public function setGroup(Group $group) {
		$this->group = $group;
	}
	
	public function getName() {
		return $this->name;
	}
	
	public function setName(string $name) {
		$this->name = $name;
	}
	
	public function getDescription() {
		return $this->description;
	}
	
	public function setDescription(string $description) {
		$this->description = $description;
	}
	
	public function getCost() {
		return $this->cost;
	}
	
	public function setCost(double $cost) {
		$this->cost = $cost;
	}
	
	public function __toString() {
		return $this->name."(".$this->cost." EUR)";
	}
}